﻿
Partial Class Hosteria_VS_CheckIn
    Inherits System.Web.UI.Page
    Protected dvCliente As Data.DataView


    Protected Sub lbSinReserva_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSinReserva.Click
        pnlSinReserva.Visible = True
        pnlSeleccion.Visible = False
    End Sub

    Protected Sub btnVerHabitaciones_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnVerHabitaciones.Click
        lblDesde.Text = Date.Today.ToShortDateString
        lblHasta.Text = Date.Today.AddDays(CDbl(txtDias.Text) - 1).ToShortDateString
        sdaHabitaciones.SelectParameters("fechaDesde").DefaultValue = lblDesde.Text
        sdaHabitaciones.SelectParameters("fechaHasta").DefaultValue = lblHasta.Text
        sdaHabitaciones.Select(DataSourceSelectArguments.Empty)
        pnlHabitaciones.Visible = True
        pnlSinReserva.Visible = False
    End Sub

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvHabitaciones.SelectedIndexChanged
        pnlCliente.Visible = True
        lblNroHabitacion.Text = gvHabitaciones.SelectedRow.Cells(1).Text
        lblTipoHabitacion.Text = gvHabitaciones.SelectedRow.Cells(2).Text
        lblDesde0.Text = lblDesde.Text
        lblHasta0.Text = lblHasta.Text
        pnlHabitaciones.Visible = False
        pnlHabitacion.Visible = True
    End Sub

    Protected Sub btnBuscarCliente_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBuscarCliente.Click
        sdaClientes.SelectParameters("Documento").DefaultValue = txtDocumento.Text
        dvCliente = CType(sdaClientes.Select(DataSourceSelectArguments.Empty), Data.DataView)
        If dvCliente.Count = 1 Then
            fvCliente.ChangeMode(FormViewMode.ReadOnly)
            pnlDatosCliente.Visible = True
            pnlCliente.Visible = False
            btnConfirmar.Visible = True
        Else
            If fvCliente.DataItemCount = 0 Then
                fvCliente.ChangeMode(FormViewMode.Insert)
                CType(fvCliente.FindControl("DocumentoTextBox"), TextBox).Text = txtDocumento.Text
                pnlCliente.Visible = False
                pnlDatosCliente.Visible = True
            End If
        End If
    End Sub

    Protected Sub InsertButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        btnConfirmar.Visible = True
    End Sub

    Protected Sub btnConfirmar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConfirmar.Click
        With sdaAsentarReserva
            .UpdateParameters("Numero").DefaultValue = lblNroHabitacion.Text
            .UpdateParameters("Estado").DefaultValue = 2 'Ocupada
            .UpdateParameters("DisponibleDesde").DefaultValue = Convert.ToDateTime(lblHasta.Text).AddDays(1).ToShortDateString
            .UpdateParameters("OcupadaDesde").DefaultValue = lblDesde.Text
            .UpdateParameters("Cliente").DefaultValue = txtDocumento.Text
            .Update()
        End With
        'With sdaBloquearHabitacion
        '.InsertParameters("IdHabitacion").DefaultValue = lblNroHabitacion.Text
        '.InsertParameters("ANombreDe").DefaultValue = CType(fvCliente.FindControl("ApellidoLabel"), Label).Text & ", " & CType(fvCliente.FindControl("NombreLabel"), Label).Text
        '.InsertParameters("Desde").DefaultValue = lblDesde.Text
        '.InsertParameters("Hasta").DefaultValue = lblHasta.Text
        '.Insert()
        'End With
        pnlSeleccion.Visible = False
        pnlDatosCliente.Visible = False
        pnlHabitacion.Visible = False
        lblCINombre.Text = CType(fvCliente.FindControl("ApellidoLabel"), Label).Text & ", " & CType(fvCliente.FindControl("NombreLabel"), Label).Text
        lblCIHabitacion.Text = lblNroHabitacion.Text
        lblCIDesde.Text = lblDesde.Text
        lblCIHasta.Text = lblHasta.Text
        pnlCheckedIn.Visible = True
    End Sub

    Protected Sub InsertButton_Click1(ByVal sender As Object, ByVal e As System.EventArgs)
        btnConfirmar.Visible = True
    End Sub
End Class
